<?php
namespace Admin\Controller;

use Think\Controller;

class ActivityController extends Controller
{

//    public function  show(){
//        $this->display();
//    }
    public function show()
    {
        if (IS_POST) {
            $model = D('Activity');
            if ($model->create(I('post.'), 1)) {
                if ($id = $model->add()) {
                    $this->success('添加成功！', U('lst?p=' . I('get.p')));
                    exit;
                }
            }
            $this->error($model->getError());
        }

        // 设置页面中的信息
        $this->assign(array(
            '_page_title' => '添加',
            '_page_btn_name' => '列表',
            '_page_btn_link' => U('lst'),
        ));
        $this->display();
    }

    public function edit()
    {
        $act_id = I('get.act_id');
        if (IS_POST) {
            $model = D('Activity');
            $info = $_POST;

                foreach ($info as $k=>$v) {
                    p($info[$k]);
                    echo "</br>";
                    echo "123";
                    $data['gene_time'] = $v['gene_time'];
                    $data['text'] = $v['text'];
                    $act_id = $v['act_id'];
                    $model->where('act_id=' . $act_id)->data($data)->save();
                    echo $model->getLastSql();
                }

                $this->error($model->getError());

        }
//    	$model = M('Activity');
//    	$data = $model->find($act_id);
//    	$this->assign('data', $data);
//
//		// 设置页面中的信息
//		$this->assign(array(
//			'_page_title' => '修改',
//			'_page_btn_name' => '列表',
//			'_page_btn_link' => U('lst'),
//		));
//            $this->display('lst');

    }

    public function delete()
    {
        $model = D('Activity');
        if ($model->delete(I('get.act_id', 0)) !== FALSE) {
            $this->success('删除成功！', U('lst', array('p' => I('get.p', 1))));
            exit;
        } else {
            $this->error($model->getError());
        }
    }

    public function lst()
    {
        $model = D('Activity');
        $data = $model->where('shop_id=1')->search();

        $this->assign(array(
            'data' => $data['data'],
            'page' => $data['page'],
        ));

        // 设置页面中的信息
        $this->assign(array(
            '_page_title' => '列表',
            '_page_btn_name' => '添加',
            '_page_btn_link' => U('add'),
        ));
        $this->display();
    }
}